package GUI.studentGUI;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.TitledBorder;

import GUI.MainGUI;
import java.awt.event.ActionListener;

import javax.swing.JPanel;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.UIManager;

import controllers.StudentController;
import entities.ComputerizedExam;
import entities.Subject;

@SuppressWarnings("serial")
public class StudentReports extends JPanel implements ActionListener {
	private JButton btnMainMenu;
	private JButton btnExit;
	private JButton btnExamCopy;
	private JLabel lblExamGrade;
	private JLabel lblGrade;
	private JComboBox comboExamID;
	private StudentController StudentCtrl;
	private JLabel lblChooseExam ;
	
	final public static int NEXT = 1;
	final public static int PREV= 2;
	
	private ArrayList<ComputerizedExam> chkdExmList;
	

	public StudentReports(StudentController StudentCtrl) {
		super();
		initialize();
		this.StudentCtrl = StudentCtrl;
		
	
	}
	/**
	 * initializing the GUI
	 */

	private void initialize() {
		setBorder(new TitledBorder(null, "Student reports: ",
				TitledBorder.LEADING, TitledBorder.TOP, null, null));
		setBackground(UIManager.getColor("InternalFrame.inactiveTitleGradient"));
		setBounds(0,0,MainGUI.setX,MainGUI.setY);
		setLayout(null);
		add(getComboExamID());
		add(getExamCopy());
		add(getExamGrade());
		add(getExit());
		add(getMainMenu());
		add(getLblGrade());
		add(GETlblChooseExam());
	}

	private JComboBox getComboExamID() {
		if (comboExamID == null) {
			comboExamID = new JComboBox();
			comboExamID.setBounds(20, 144, 429, 27);
			comboExamID.addActionListener(this);
		}
		return comboExamID;
	}

	private JButton getExamCopy() {
		if (btnExamCopy == null) {
			btnExamCopy = new JButton("Get exam copy");
			btnExamCopy.setFont(new Font("Tahoma", Font.PLAIN, 12));
			btnExamCopy.setBounds(186, 405, 135, 29);
			btnExamCopy.addActionListener(this);
		}
		return btnExamCopy;
	}

	private JLabel getExamGrade() {
		if (lblExamGrade == null) {
			lblExamGrade = new JLabel("Exam grade:");
			lblExamGrade.setBounds(57, 24, 81, 14);
		}
		return lblExamGrade;
	}

	private JButton getExit() {
		if (btnExit == null) {
			btnExit = new JButton("Exit");
			btnExit.setBounds(416, 447, 56, 30);
			btnExit.addActionListener(this);
		}
		return btnExit;
	}

	private JButton getMainMenu() {
		if (btnMainMenu == null) {
			btnMainMenu = new JButton("Main menu");
			btnMainMenu.setBounds(28, 447, 110, 29);
			btnMainMenu.addActionListener(this);
		}
		return btnMainMenu;
	}
	
	private JLabel GETlblChooseExam()
	{
		if (lblChooseExam==null)
		{
			lblChooseExam = new JLabel("Choose exam:");
			lblChooseExam.setBounds(28, 126, 127, 19);			
		}
		return lblChooseExam;
	}
	/**
	 * 
	 * @param exmLst
	 */
	public void addChekdExams(ArrayList<ComputerizedExam> exmLst) {
		chkdExmList= new ArrayList<ComputerizedExam>();
		chkdExmList.addAll(0, exmLst);
		for (int i = 0; i < (exmLst.size()); i++)
			comboExamID.addItem(chkdExmList.get(i).getExamCode());
		comboExamID.addActionListener(this);
	}

	

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == btnExit) // logout
			StudentCtrl.handleStudentGUI(StudentController.EXIT);
		if (e.getSource() == btnMainMenu) // return to user main screen
			StudentCtrl.handleStudentGUI(StudentController.MAIN);
		if (e.getSource() == btnExamCopy) {
			StudentCtrl.handleStudentGUI(StudentController.MANUAL_EXAM);//  download copy file
		}
		if (e.getSource() == comboExamID) {
			comboExamID.getSelectedItem();
		}
	}

	private JLabel getLblGrade() {
		if (lblGrade == null) {
			lblGrade = new JLabel("grade:");
			lblGrade.setBounds(57, 49, 65, 31);
		}
		return lblGrade;
	}
}
